package com.example.myapplication.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;


import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.myapplication.R;
import com.example.myapplication.bean.ImportBean;
import com.example.myapplication.bean.MemorandumBean;

import java.util.ArrayList;

public class MemorandumAdapter extends ArrayAdapter<MemorandumBean> {
    private int resourceId;
    private Context context;
    private ArrayList<MemorandumBean> dataSet;

    public MemorandumAdapter(@NonNull Context context, int resource, @NonNull ArrayList<MemorandumBean> objects) {
        super(context, resource, objects);
        this.context = context;
        this.resourceId = resource;
        this.dataSet = objects;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        MemorandumHolder memorandumHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(resourceId, null);
            memorandumHolder = new MemorandumHolder();
            memorandumHolder.title_t = convertView.findViewById(R.id.til_txt);
            memorandumHolder.time_t = convertView.findViewById(R.id.date_txt);
            memorandumHolder.infor_t = convertView.findViewById(R.id.infor_txt);
            convertView.setTag(memorandumHolder);
        } else {
            memorandumHolder = (MemorandumHolder) convertView.getTag();
        }
        final MemorandumBean memorandumBean = dataSet.get(position);
        memorandumHolder.title_t.setText(memorandumBean.getTitle());
        memorandumHolder.time_t.setText(memorandumBean.getTime());
        memorandumHolder.infor_t.setText(memorandumBean.getInfor());
        return convertView;
    }

    public class MemorandumHolder {
        TextView title_t;
        TextView time_t;
        TextView infor_t;
    }
}
